 function _openWin(name,id) {
    
    if(id){
        pageParam = {id: id}
    }else{
        pageParam = ''
    }
    api.openWin({
        name: name,
        url: name + '.html',
        opaque: true,
        vScrollBarEnabled: false,
        delay: 200,
        pageParam:pageParam

    });
}
function openEditWin(title,thumb,id,qishu){
	
    var pageParam = {title: title,thumb: thumb,id: id,qishu:qishu}
    //alert(JSON.stringify(pageParam))
    
	api.openWin({
        name: 'editShare',
        url:'editShare.html',
        opaque: true,
        vScrollBarEnabled: false,
        delay: 200,
        pageParam:pageParam,
        reload:true

    });
}
apiready = function(){
  var name = api.frameName;
	setbounces(name,true);
	var total = '';
    var uid = api.pageParam.uid;
  
    getBuyRecord(uid,true);
    function getBuyRecord(uid,isReload,currentPage,sid) {
    var pageSize = 10;
    currentPage=isReload?0:currentPage;
    	api.ajax({
        url: 'http://wap.jqmao.cn/unfinished',
        method: 'post',
        data: {
            values: {uid: uid, pageSize: pageSize,currentPage:currentPage}
        }
    }, function (ret, err) {
			
        if (ret) {
        		//alert(JSON.stringify(ret))
            total = ret['total']
            var content = $api.byId('unfinished-content');
            var tpl = $api.byId('unfinished-template').text;
            var tempFn = doT.template(tpl);
            //alert($api.getStorage('type'));
            //alert(type)
            api.hideProgress();

            if (isReload) {
                $api.setStorage("currentPage", 0);        // 重新设置为0
                $api.html(content, tempFn(ret['listItems']));
                
            } else {
                $api.append(content, tempFn(ret['listItems']));
            }


        } else {
           //alert(JSON.stringify(err));
        }
        
    });
    }

    //下拉刷新
    api.setCustomRefreshHeaderInfo({
            bgColor : '#f0f0f0',
            image: {
        pull: 'widget://image/refresh/1.png', 
        transform: [
            'widget://image/refresh/1.png', 
            'widget://image/refresh/2.png',
            'widget://image/refresh/3.png',
            'widget://image/refresh/4.png',
            'widget://image/refresh/5.png',
            'widget://image/refresh/6.png',
            'widget://image/refresh/7.png'
        ],
        load: [ 
            'widget://image/refresh/1.png', 
            'widget://image/refresh/2.png',
            'widget://image/refresh/3.png', 
            'widget://image/refresh/4.png',
            'widget://image/refresh/5.png'
        ]
    }
        }, function() {
            //下拉刷新被触发，自动进入加载状态，使用 api.refreshHeaderLoadDone() 手动结束加载中状态
            setTimeout(function(){
             
            var typeName = $api.getStorage('type');
	       var typeName = $api.getStorage('type');
       getBuyRecord(uid,true);
     
        api.refreshHeaderLoadDone();
	            }, 800);
           
      });
    


//上拉加载
    api.addEventListener({

        name: 'scrolltobottom',
        extra: {
            threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
        }
    }, function (ret, err) {
        $("#more").show();
        
        var _page=parseInt($api.getStorage("currentPage"));
        if(_page+10<=total){
         	getBuyRecord(uid,false,_page+10);
        	$api.setStorage("currentPage", _page+10); // 页码+1
        }else{
            $("#more").hide();
        }
      
       
    });

    

}

    